Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extra functionality to FloatEdit #3889

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vallsv
Copy link
Contributor

@vallsv vallsv commented Jun 26, 2023

Closes #3888

This PR mostly provides extra validators that i have designed during the years.

It allows configurable behaviours like:

  • Empty input as None
  • Fast edition of the dot . from the input
  • Included/excluded float min/max boundaries
  • Basic support for quantities
  • Plus a bit more accurate value will is it not edited by the user

This PR also add some tests to the FloatEdit.

Changelog:

  • Added support to custom validators to FloatEdit widget
  • Added extra validators to share common behaviours

@vallsv
Copy link
Contributor Author

vallsv commented Jun 27, 2023

Tested manually with pyside6-6.5.1.1, sounds like it's ok

@vallsv vallsv added this to the 2.0.0 milestone Jun 27, 2023
@vallsv vallsv self-assigned this Jun 27, 2023
Copy link
Member

@t20100 t20100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a bit of duplicated code between AdvancedDoubleValidator and AdvancedDoublePintValidator. If possible that'd be best to share it.
Also why providing 2 classes (e.g., DoubleValidator and AdvancedDoubleValidator) rather than only the advanced one which by default provides what the default one does?

Comment on lines +56 to +61
def keyPressEvent(self, event: qt.QEvent):
result = super(FloatEdit, self).keyPressEvent(event)
if event.isAccepted():
self.__wasModified = True
return result

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be useless (__wasModified is never used)

Suggested change
def keyPressEvent(self, event: qt.QEvent):
result = super(FloatEdit, self).keyPressEvent(event)
if event.isAccepted():
self.__wasModified = True
return result

"""
self.__allowEmpty = allow

def setIncludedBound(self, minBoundIncluded: bool, maxBoundIncluded: bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a getter

self.__allowEmpty = False
self.__boundIncluded = True, True

def setAllowEmpty(self, allow: bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a getter

"""
self.__allowEmpty = allow

def setIncludedBound(self, minBoundIncluded: bool, maxBoundIncluded: bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a getter

self.__allowEmpty: bool = False
self.__boundIncluded: Tuple[bool, bool] = (True, True)

def setAllowEmpty(self, allow: bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a getter

inputText = inputText[0:pos] + locale.decimalPoint() + inputText[pos:]
pos = pos + 1

print(pos, inputText, inputText[pos - 1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(pos, inputText, inputText[pos - 1])

from silx.gui import qt


class CustomValidator:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a name with more meaning, e.g. ConverterValidatorMixIn

@vallsv vallsv modified the milestones: 2.0.0, Next release Sep 8, 2023
@t20100 t20100 removed this from the Next release milestone Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extended FloatEdit
2 participants